﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>@ViewBag.ProjectName-Shipeng.HRMS.出品</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="@ViewBag.LogoIcon">
    <link rel="stylesheet" href="~/lib/layui/css/layui.css?v=@Shipeng.Util.GlobalContext.GetVersion()" media="all">
    <link rel="stylesheet" href="~/css/login.css?v=@Shipeng.Util.GlobalContext.GetVersion()" media="all">
</head>

<body>
    <script src="~/lib/jquery-3.4.1/jquery-3.4.1.min.js?v=@Shipeng.Util.GlobalContext.GetVersion()" charset="utf-8"></script>
    <script src="~/js/cookie/jquery.cookie.js?v=@Shipeng.Util.GlobalContext.GetVersion()"></script>
    <script src="~/js/md5/base64.js?v=@Shipeng.Util.GlobalContext.GetVersion()"></script>
    <script src="~/js/md5/jquery.md5.js?v=@Shipeng.Util.GlobalContext.GetVersion()"></script>
    <script src="~/lib/layui/layui.js?v=@Shipeng.Util.GlobalContext.GetVersion()" charset="utf-8"></script>
    <script src="~/js/lay-config.js?v=@Shipeng.Util.GlobalContext.GetVersion()" charset="utf-8"></script>
    <script src="~/js/framework-ui.js?v=@Shipeng.Util.GlobalContext.GetVersion()"></script>
    <script>
        layui.use(['jquery', 'form', 'table', 'common', 'commonTable', 'echarts'], function () {
        });
    </script>
    @*动画特效*@
    <div id="starsBox"></div>
    <div class="layui-container">
        <div class="admin-login-background">
            <div class="layui-form login-form">
                <div class="logo-title">
                    <h1>@ViewBag.ProjectName</h1>
                </div>
                <form class="layui-form" action="">
                    <div class="layui-form-item">
                        <label class="layui-icon layui-icon-username" for="username"></label>
                        <input type="text" id="username" lay-verify="required|account" placeholder="用户名" autocomplete="off" class="layui-input" value="@ViewBag.UserName">
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-icon layui-icon-password" for="password"></label>
                        <input type="password" id="password" lay-verify="required|password" placeholder="密码" autocomplete="off" class="layui-input" value="@ViewBag.Password">
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-icon layui-icon-vercode" for="captcha"></label>
                        <div class="code">
                            <input id="captcha" type="text" name="captcha" lay-verify="required|captcha" placeholder="图形验证码" autocomplete="off" class="layui-input verification captcha">
                            <canvas id="canvas" width="100" height="43"></canvas>
                        </div>
                    </div>
                    <div class="layui-form-item layui-hide">
                        <select id="wchost" name="wchost" lay-verify="required">
                        </select>
                    </div>
                    <div class="layui-form-item">
                        <span>
                            <input type="checkbox" name="remember_user" id="remember_user" lay-skin="primary" style="vertical-align:middle;" value="true">
                            <span style="color:#FFFFCE;vertical-align:middle;">记住密码</span>
                        </span>
                    </div>
                    <div class="row" style="margin-top:5px;color:orange;">
                        <span>测试账号admin,密码0000</span>
                    </div>
                    <div class="layui-form-item">
                        <div class="login_tips"></div>
                        <button id="login_button" class="layui-btn layui-btn-fluid" style="background-color:#FFFFCE;color:orange" lay-submit="" lay-filter="login">登 入</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <script src="~/js/login.js?v=@Shipeng.Util.GlobalContext.GetVersion()"></script>
    <script>
        //模式
        var SqlMode = '@ViewBag.SqlMode';
        (function ($) {
            var show_num = [];
            $.login = {
                formMessage: function (msg) {
                    $('.login_tips').find('.tips_msg').remove();
                    $('.login_tips').append('<div class="tips_msg"><i class="fa fa-question-circle"></i>' + msg + '</div>');
                },
                init: function () {
                    $("#canvas").click(function () {
                        draw(show_num);
                    });
                    var login_error = top.$.cookie('Shipeng.HRMS.login_error');
                    if (login_error != null) {
                        switch (login_error) {
                            case "overdue":
                                $.login.formMessage('系统登录已超时,请重新登录');
                                break;
                            case "OnLine":
                                $.login.formMessage('您的帐号已在其它地方登录,请重新登录');
                                break;
                            case "-1":
                                $.login.formMessage('系统未知错误,请重新登录');
                                break;
                        }
                        top.$.cookie('Shipeng.HRMS.login_error', '', { path: "/", expires: -1 });
                    }
                },
                checkLogin: function () {
                    $.ajax({
                        url: "/Login/CheckLoginState?v=" + new Date().Format("yyyy-MM-dd hh:mm:ss"),
                        type: "post",
                        async: false,
                        dataType: "json",
                        success: function (data) {
                            if (data.state == "success") {
                                var url = $.cookie('wc_returnurl');
                                if (url != null) {
                                    window.location.href = '@Url.Content("~/Home/Index")' + "#/" + url;
                                    $.cookie('wc_returnurl', '', { path: "/", expires: -1 });
                                }
                                else {
                                    window.location.href = '@Url.Content("~/Home/Index")';
                                }
                            }
                        }
                    });
                }
            };
            $(function () {
                if (SqlMode =='TenantSql') {
                    $('#wchost').parent().removeClass('layui-hide');
                }
                else {
                    $('#wchost').parent().addClass('layui-hide');
                    $('#wchost').removeAttr('lay-verify');
                }
                $.login.init();
                $.login.checkLogin();
                $("#wchost").bindSelect({
                    url: "/Login/GetListJsonByLogin",
                    id: "F_HostUrl",
                    text: "F_ProjectName"
                });
                draw(show_num);
                if ($.cookie("remember_user")) {
                    $("#remember_user").prop("checked", true);
                    $("#username").val($.cookie("username"));
                    $("#password").val(Base64.decode($.cookie("password")));
                }
            });
            function saveUserInfo() {
                if ($("#remember_user").prop("checked") == true) {
                    var user_name = $("#username").val();
                    var user_password = $("#password").val();
                    $.cookie("remember_user", "true", {
                        expires: 7
                    }); // 存储一个带7天期限的 cookie
                    $.cookie("username", user_name, {
                        expires: 7
                    }); // 存储一个带7天期限的 cookie
                    $.cookie("password", Base64.encode(user_password), {
                        expires: 7
                    }); // 存储一个带7天期限的 cookie
                } else {
                    $.cookie("remember_user", "false", {
                        expires: -1
                    }); // 删除 cookie
                    $.cookie("username", '', {
                        expires: -1
                    });
                    $.cookie("password", '', {
                        expires: -1
                    });
                }
            }
            layui.use(['form'], function () {
                var form = layui.form,
                    layer = layui.layer;
                // 登录过期的时候，跳出ifram框架
                if (top.location != self.location) top.location = self.location;

                // 进行登录操作
                form.on('submit(login)', function (data) {
                    saveUserInfo();
                    data = data.field;
                    if (data.username == '') {
                        layer.msg('用户名不能为空');
                        return false;
                    }
                    if (data.password == '') {
                        layer.msg('密码不能为空');
                        return false;
                    }
                    var num = show_num.join("");
                    if (data.captcha == '') {
                        layer.msg('验证码不能为空');
                        return false;
                    }
                    else if (num != data.captcha.toLowerCase()) {
                        layer.msg('验证码错误');
                        draw(show_num)
                        return false;
                    }
                    $("#login_button").empty();
                    $("#login_button").attr('disabled', 'disabled').html("loading...");
                    $.ajax({
                        url: "/Login/CheckLogin?v=" + new Date().Format("yyyy-MM-dd hh:mm:ss"),
                        data: { username: $.trim($('#username').val()), localurl: $('#wchost').val(), password: $.md5($.trim($('#password').val())) },
                        type: "post",
                        dataType: "json",
                        success: function (data) {
                            if (data.state == "success") {
                                $("#login_button").empty();
                                $("#login_button").html("登录成功，正在跳转...");
                                var realurl = $.cookie('wc_realreturnurl');
                                if (realurl != null) {
                                    window.location.href = realurl;
                                    $.cookie('wc_realreturnurl', '', { path: "/", expires: -1 });
                                    $.cookie('wc_returnurl', '', { path: "/", expires: -1 });
                                }
                                else {
                                    var url = $.cookie('wc_returnurl');
                                    if (url != null) {
                                        window.location.href = '@Url.Content("~/Home/Index")' + "#/" + url;
                                        $.cookie('wc_returnurl', '', { path: "/", expires: -1 });
                                    }
                                    else {
                                        window.location.href = '@Url.Content("~/Home/Index")';
                                    }
                                }
                            } else {
                                $("#login_button").empty();
                                $("#login_button").removeAttr('disabled').html("登 入");
                                draw(show_num);
                                layer.msg(data.message);
                                $.login.formMessage(data.message);
                            }
                        },
                        error: function () {
                            $("#login_button").empty();
                            $("#login_button").removeAttr('disabled').html("登 入");
                            draw(show_num);
                            layer.msg("系统未知错误,请重新登录");
                            $.login.formMessage("系统未知错误,请重新登录");
                        }

                    });

                    return false;
                });
            });
        })(jQuery);
    </script>
</body>
</html>